home *** CD-ROM | disk | FTP | other *** search
- Path: pegasus.montclair.edu!harmon
- From: harmon@pegasus.montclair.edu (Derek Harmon)
- Newsgroups: comp.lang.c
- Subject: Re: How to open include path by fopen in DOS C program?
- Date: 12 Feb 1996 15:56:02 -0500
- Organization: Montclair State University
- Message-ID: <harmon.824157381@pegasus.montclair.edu>
- References: <4fhkvd$120@news.hkstandard.com>
- NNTP-Posting-Host: pegasus.montclair.edu
- X-Newsreader: NN version 6.5.0 #68 (NOV)
-
- khtse@hkstandard.com (khtse) writes:
- > It can open file name by fopen only but not include path name under
- >DOS C program, so how to solve it?
-
- FILE *fp;
-
- if ((fp = fopen("\\TEST\\CONFIG.DAT", "rt)) == NULL) {
- fputs(stderr,"Cannot open Config File for reading.");
- return 1;
- }
-
- Notice the \\'s in the filespec string, these are necessary because C
- defines \ as an escape character, which you normally use in \n or \t. To
- actually have the C compiler include a \ in a piece of text, you must use
- \\. In a filespec, fopen for DOS will then convert to D:\TEST\CONFIG.DAT,
- where D is your current drive. Similarly, a filespec such as "F:\\FOO.BAR"
- would look in the root-directory of drive F:.
-
- > And in the network environment, if C program is reading the text files
- >and the other pc to write and update this text file, what will happen?
-
- Your PC will explode. B) Actually if you have something to watchdog
- your system like SHARE.EXE for DOS 3.3 and later, you will get a Sharing
- Violation. If you want to program to allow this to occur, Share or most
- equivalent network drivers feature functions that will lock files and records,
- to prevent the problem you describe from happening. In general, your Read
- and Write functions would have to:
-
- 1. Attempt to lock the record(s) or file(s) you wish to read/write.
- 2. When Share or your Network driver gives your program exclusive
- permission to those records/files, you read/write them.
- 3. Subsequently you must unlock the record(s) or file(s) to which you
- requested a read or write.
-
- Usually the implementation is that multiple concurrent reads are permis-
- sible, but if any writing is being done, reads will be blocked by DOS or the
- network operating system.
-
- For details on writing Read/Write code for use with DOS's Share, consult
- any good PC/DOS Programmer's Manual. For other networks, consult their
- API references. The specifics are OS-specific and are best asked in another
- more relevent newsgroup.
- -- Stone
-
- --
- # Derek Harmon (aka Stonelight) harmon@pegasus.montclair.edu
- # - Computer Science Undergrad, Montclair State University, NJ
- # - My views are my own, nobody else is this creative. 3;)>
- ... This cookie is void where prohibited, licensed, or taxed.
-